<?php echo $header ?>
<div class="content projects douban_email">
  <div class="container">

 <h3>群发豆邮 ...</h3>
 
 <div class="email">
 
 <label>标题</label>
 <input id ="msg_title" type="text" placeholder="豆邮标题" class ="span10">
 
 <label>内容</label>
 <textarea id ="msg_content" rows="4" class ="span10" placeholder="豆邮内容"></textarea>
 
 </div>

 <label>选择群发组</label>
 <div class="btn-group">
  <button class="btn    btn_following">我关注的人</button>
  <button class="btn   btn_followers">关注我的人</button>
  <button class="btn  btn_each">相互关注的人</button>
</div>

<div class ="span10 friendlist" fid="0">


</div>

<div style="clear:both;"></div>

<div ><label>预计发送时间</label></div>

<div class="need_score"></div>

<div><button class="btn btn-info btn_send"> 发送</button></div>
   
 <div class="border"></div>
  </div>
</div>

<?php echo $footer ?>

<script language="javascript">

$(document).ready(function(){

	$('.btn_following').click(function(){

        $('.btn').each(function(){
            $(this).removeClass('btn-warning');
            });
		var url = "<?php echo $ajaxUrl['following'] ?>";
		$(this).addClass('btn-warning');

		$(".friendlist").attr('fid','following_list');
		$(".friendlist").html("<img src='public/img/common/loading.gif'>").load(url,function(){

			var total = 0;
			$('.following_list').each(function(){
				if($(this).css('display') == "block")
				{
					total = $(this).attr('total');
				}
			});

			$('.need_score').empty();
			$('.need_score').append("<label>需要消耗的积分"+total*1+"</label>");
			
			});

	
	});

	

	$('.btn_followers').click(function(){
		
		$('.btn').each(function(){
            $(this).removeClass('btn-warning');
            });
		var url = "<?php echo $ajaxUrl['followers'] ?>";
		$(this).addClass('btn-warning');
		$(".friendlist").attr('fid','followers_list');
		$(".friendlist").html("<img src='public/img/common/loading.gif'>").load(url,function(){

			var total = 0;
			total = $('.followers_list').attr('total');

			$('.need_score').empty();
			$('.need_score').append("<label>需要消耗的积分"+total*1+"</label>");
		});

		
    });


$('.btn_each').click(function(){

	$('.btn').each(function(){
        $(this).removeClass('btn-warning');
        });
		var url = "<?php echo $ajaxUrl['each'] ?>";
		$(this).addClass('btn-warning');
		$(".friendlist").attr('fid','each_list');
		$(".friendlist").html("<img src='public/img/common/loading.gif'>").load(url,function(){
			var total = 0;
			total = $('.each_list').attr('total');
			$('.need_score').empty();
			$('.need_score').append("<label>需要消耗的积分"+total*1+"</label>");
		});
		
		});

   $('.btn_send').click(function(){

	   var type = $('.friendlist').attr('fid');

	   var title =$('#msg_title').val();
	   if(!title){
		   alert('输入标题呀，亲..');
		   return false;
	   }

	   var content = $('#msg_content').val();
	   if(!content){
		   alert("没有内容，系统会崩溃的..");
		   return false;
		}

	   var arg = "";
	   var toArg  = new Array();
	   if(type == "following_list"){
		   $('.following_list').each(function(){
				if($(this).css('display') == "block")
				{
					 $(this).find('.friend_info').each(function(){
						 var uid = $(this).find('a').attr('uid');
								arg = arg+uid+",";
						 });
					
				}
			});
	   }

	   if(type == "followers_list"){
		   $('.followers_list > .friend_info').each(function(){
			   var uid = $(this).find('a').attr('uid');
			   arg = arg+uid+",";
			   });
	   }

	   if(type == "each_list"){
		   $('.each_list > .friend_info').each(function(){
			   var uid = $(this).find('a').attr('uid');
			   arg += uid+",";
			   });
	   }

	   $.post("<?php echo $ajaxUrl['add']?>",{'title':title,'content':content,'idList':arg},function(data){

		  if(data.status == '1'){

			  var msgID = data.msgID
			  $.post("<?php echo $ajaxUrl['send']?>",{'msgID':msgID},function(){
				  });
		  }
		},'json');
	   
	   });
});

</script>